import Vue from 'vue';
import axios from "axios";
import store from "../store";

const request = axios.create({
  baseURL: 'http://121.89.205.189:3000/api',
  timeout: 60 * 1000,
})

request.interceptors.request.use(function (config) {
  return config;
}, function (error) {
  return Promise.reject(error);
});

request.interceptors.response.use(function (response) {
  if (response.data.data && response.data.data.token) {
    store.commit('set_token', response.data.data.token)
  }

  return response.data;
}, function (error) {
  return Promise.reject(error);
});

export default request